const mysql = require('mysql2/promise');

async function addWinterClothes() {
  const connection = await mysql.createConnection({
    host: '127.0.0.1',
    user: 'root',
    password: '302108jw302',
    database: 'wardrobe_db'
  });

  console.log('❄️ 开始添加严寒天气适用的衣服...');

  try {
    // 添加适合严寒天气的衣服
    const winterClothes = [
      // 保暖外套
      [1, 3, '黑色羽绒服', '黑色', '#000000', 'Uniqlo', 'winter', 'casual', 'available', 599.00, '2024-01-15', '保暖羽绒服，适合严寒天气', true],
      [1, 3, '深蓝色棉衣', '深蓝色', '#000080', 'ZARA', 'winter', 'casual', 'available', 399.00, '2024-01-20', '厚棉衣，防风保暖', false],
      [1, 3, '灰色毛呢大衣', '灰色', '#808080', 'H&M', 'winter', 'formal', 'available', 799.00, '2024-02-01', '毛呢大衣，保暖又正式', false],
      [1, 3, '军绿色冲锋衣', '军绿色', '#556B2F', 'Columbia', 'winter', 'sport', 'available', 899.00, '2024-01-25', '防风防水冲锋衣', false],
      
      // 保暖上装
      [1, 1, '深红色厚毛衣', '深红色', '#8B0000', 'ZARA', 'winter', 'casual', 'available', 299.00, '2024-01-30', '厚羊毛毛衣，非常保暖', true],
      [1, 1, '黑色高领毛衣', '黑色', '#000000', 'Uniqlo', 'winter', 'casual', 'available', 199.00, '2024-02-05', '高领设计，保暖脖子', false],
      [1, 1, '深灰色羊绒衫', '深灰色', '#2F4F4F', 'COS', 'winter', 'business', 'available', 599.00, '2024-01-18', '羊绒材质，轻薄保暖', false],
      [1, 1, '棕色厚卫衣', '棕色', '#8B4513', 'Nike', 'winter', 'sport', 'available', 399.00, '2024-02-10', '加绒卫衣，运动保暖', false],
      
      // 保暖下装
      [1, 2, '黑色加绒裤', '黑色', '#000000', 'Uniqlo', 'winter', 'casual', 'available', 199.00, '2024-01-22', '内里加绒，保暖舒适', false],
      [1, 2, '深蓝色厚牛仔裤', '深蓝色', '#000080', 'Levis', 'winter', 'casual', 'available', 499.00, '2024-02-03', '厚款牛仔裤，防风', false],
      [1, 2, '灰色羊毛裤', '灰色', '#808080', 'ZARA', 'winter', 'business', 'available', 399.00, '2024-01-28', '羊毛材质，正式保暖', false],
      
      // 保暖鞋子
      [1, 4, '黑色雪地靴', '黑色', '#000000', 'UGG', 'winter', 'casual', 'available', 1299.00, '2024-01-12', '真皮雪地靴，防滑保暖', true],
      [1, 4, '棕色马丁靴', '棕色', '#8B4513', 'Dr.Martens', 'winter', 'casual', 'available', 899.00, '2024-01-26', '经典马丁靴，保暖防滑', false],
      [1, 4, '深蓝色保暖运动鞋', '深蓝色', '#000080', 'Nike', 'winter', 'sport', 'available', 699.00, '2024-02-08', '加绒运动鞋，运动保暖', false],
      [1, 4, '黑色保暖皮鞋', '黑色', '#000000', 'ZARA', 'winter', 'business', 'available', 599.00, '2024-01-16', '商务皮鞋，内里保暖', false],
      
      // 保暖配饰
      [1, 5, '深灰色羊毛围巾', '深灰色', '#2F4F4F', 'ZARA', 'winter', 'casual', 'available', 199.00, '2024-01-14', '羊毛围巾，柔软保暖', false],
      [1, 5, '黑色针织帽', '黑色', '#000000', 'Uniqlo', 'winter', 'casual', 'available', 99.00, '2024-01-21', '针织毛线帽，保暖头部', false],
      [1, 5, '深棕色皮手套', '深棕色', '#654321', 'ZARA', 'winter', 'business', 'available', 299.00, '2024-02-02', '真皮手套，保暖防风', false],
      [1, 5, '黑色保暖袜子', '黑色', '#000000', 'Uniqlo', 'winter', 'casual', 'available', 59.00, '2024-01-19', '厚毛袜，保暖双脚', false]
    ];

    const sql = `INSERT INTO clothing (user_id, category_id, name, color, color_hex, brand, season, style, status, price, purchase_date, notes, is_favorite, created_at, updated_at) VALUES ?`;
    
    // 为每条记录添加时间戳
    const clothingDataWithTimestamp = winterClothes.map(row => [
      ...row,
      new Date(),
      new Date()
    ]);

    await connection.query(sql, [clothingDataWithTimestamp]);
    
    console.log(`✅ 成功添加了 ${winterClothes.length} 件严寒天气衣服`);
    
    // 查询总数
    const [rows] = await connection.query('SELECT COUNT(*) as count FROM clothing WHERE user_id = 1');
    console.log(`📊 用户现在总共有 ${rows[0].count} 件衣服`);
    
    // 查询严寒天气适用的衣服数量
    const [winterRows] = await connection.query(`
      SELECT COUNT(*) as count FROM clothing 
      WHERE user_id = 1 AND (
        name LIKE '%羽绒%' OR name LIKE '%棉衣%' OR name LIKE '%毛衣%' OR 
        name LIKE '%保暖%' OR name LIKE '%厚%' OR name LIKE '%雪地靴%' OR
        name LIKE '%围巾%' OR name LIKE '%手套%' OR season = 'winter'
      )
    `);
    console.log(`❄️ 其中适合严寒天气的衣服有 ${winterRows[0].count} 件`);
    
  } catch (error) {
    console.error('❌ 添加严寒天气衣服失败:', error);
  } finally {
    await connection.end();
  }
}

addWinterClothes();
